<div class="dataCount mt20 mb20" style="margin-left: 30px;margin-right: 30px;">
    <form  id="searchForm" action="{{url("material/materialGroup")}}"  method="post">
        <div class="nav" style="height:85px;">
            <div>
                <button id="add_btn" style="width:150px" type="button">添加素材组</button>
            </div>
        </div>
    </form>
    <table class="list-tb">
        <tr>
            <th width="3%"><input type="checkbox"  class="ckb_manage"  />全选</th>
            <th width="5%">标题</th>
            <th width="5%">类型</th>
            <th width="10%">操作</th>
        </tr>
        {% if list %}
        {% for material in list %}
        <tr>
            <td > <input type="checkbox" name="ids[]"class="ckb" videoId="{{material['id']}}"  value="{{material['id']}}" /></td>
            <td  >{{material['title']}}</td>
            <td  >
                {% if material['type'] == 1  %}
                图片
                {% elseif material['type'] == 2 %}
                视频
                {% elseif material['type'] == 3 %}
                音频
                {% endif %}
            </td>
            <td  >
                <a href="{{url('material/material')}}?id={{material['id']}}" >素材管理</a>  |

                <a href="{{url('material/materialGroupEdit')}}?id={{material['id']}}" >编辑</a> |

                <a href="javascript:;"  class="del" objectId="{{material['id']}}" >删除</a>
            </td>
        </tr>
        {% endfor %}
        {% else  %}
        <tr>
            <td colspan="10">
                <div class="noData">
                    <p class="info">没有符合条件的结果</p>
                </div>
            </td>
        </tr>
        {% endif %}
        <input type="hidden" value="{{url("material/materialGroupAdd")}}" id="addUrl" />
        <input type="hidden" value="{{url("material/ajaxMaterialGroupDel")}}" id="delUrl" />
    </table>
    <div class="page mt30">
        {{ show }}
    </div>
</div>

<script>
    /*
     * 提交搜索表单
     * 
     */
    var submitSearchForm = function () {
        $("#searchForm").submit();
    };


    /*
     * 添加按钮跳转
     * 
     */
    var addButHref = function () {
        var url = $("#addUrl").val();
        location.href = url;
    };

    /*
     * 删除
     * @returns {undefined}
     */
    var ajaxDel = function () {
        var id = $(this).attr("objectId");
        $.msgbox({
            height: 120,
            content: {type: 'confirm', content: '是否要删除此素材组？'},
            onClose: function (result) {
                if (result) {
                    var url = $("#delUrl").val();
                    if (id == "") {
                        alert("请选择素材组");
                        return false;
                    }
                    var json = {
                        "id": id,
                    };
                    var successFunction = function (data) {
                        if (data.status == 200) {
                            alert("删除成功");
                            window.location.reload();
                        } else if (data.status == -1) {
                            alert(data.info);
                        }
                    };
                    var errorFunction = function () {

                    };
                    $.ajax({
                        url: url,
                        data: json,
                        type: "post",
                        error: errorFunction,
                        success: successFunction
                    });
                }
            }
        });//msgbox
    }


    $(window).load(function () {
        $('#search_btn').bind('click', submitSearchForm);
        $('.del').bind('click', ajaxDel);
        $('#add_btn').bind('click', addButHref);
    });



</script>